package com.zbkj.business.sys.interview;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 人事面登记表
 * @create: 2025-03-29 14:21:49
 **/
@Service("examInterview")
@Slf4j
public class ExamInterviewService{

    @Resource
    ExamInterviewDao examInterviewDao;

    /**
     * 添加人事面登记表,获取id数据
     *
     * @param cdoRequest - id:编号
     *                   - interview_sun:题
     *                   - interview_time:时间段id
     *                   - interview_moon:答案
     *                   - interview_name:姓名
     *                   - interview_position:职位
     *                   - interview_address:住址
     *                   - interview_circumference:备注
     *                   - created_at:
     *                   - updated_at:
     * @return
     * @author 
     * @create: 2025-03-29 14:21:49
     */
    @OpenApi
    public Return addExamInterview(CDO cdoRequest) {
        examInterviewDao.addExamInterview(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("id")) {
            cdoResult.set("id", cdoRequest.get("id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，更新人事面登记表数据
     *
     * @param cdoRequest - id:编号
     *                   - interview_sun:题
     *                   - interview_time:时间段id
     *                   - interview_moon:答案
     *                   - interview_name:姓名
     *                   - interview_position:职位
     *                   - interview_address:住址
     *                   - interview_circumference:备注
     *                   - created_at:
     *                   - updated_at:
     * @return
     * @author 
     * @create: 2025-03-29 14:21:49
     */
    @OpenApi
    public Return updateExamInterviewById(CDO cdoRequest) {
        int affectedRows = examInterviewDao.updateExamInterviewById(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，删除人事面登记表数据
     *
     * @param cdoRequest - id:编号
     * @return
     * @author 
     * @create: 2025-03-29 14:21:49
     */
    //@OpenApi
    public Return deleteExamInterviewById(CDO cdoRequest){
        int affectedRows = examInterviewDao.deleteExamInterviewById(cdoRequest.getInteger("id"));
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除人事面登记表数据
     *
     * @param cdoRequest
     * @return
     * @author 
     * @create: 2025-03-29 14:21:49
     */
    //@OpenApi
    public Return deleteExamInterview(CDO cdoRequest) {
        int affectedRows = examInterviewDao.deleteExamInterview(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取人事面登记表数据
     *
     * @param cdoRequest - id:编号
     * @return
     * @author 
     * @create: 2025-03-29 14:21:49
     */
    @OpenApi
    public Return getExamInterviewById(CDO cdoRequest) {
        CDO cdoMapperResult = examInterviewDao.getExamInterviewById(cdoRequest.getInteger("id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据混合条件，获取人事面登记表数据
     *
     * @param cdoRequest - id:编号
     * @return
     * @author 
     * @create: 2025-03-29 14:21:49
     */
    @OpenApi
    public Return getExamInterview(CDO cdoRequest) {
        CDO cdoMapperResult = examInterviewDao.getExamInterview(cdoRequest);
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取人事面登记表数据列表
     *
     * @param cdoRequest
     * @return
     * @author 
     * @create: 2025-03-29 14:21:49
     */
    @OpenApi
    public Return getExamInterviewList(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.containsKey("pageIndex") ? cdoRequest.getInteger("pageIndex") : 0;
        int recordSize = cdoRequest.containsKey("recordSize") ? cdoRequest.getInteger("recordSize") : 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = examInterviewDao.getExamInterviewList(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = examInterviewDao.getExamInterviewListCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据混合条件，获取人事面登记表数据列表
     *
     * @param cdoRequest - id:编号
     * @return
     * @author 
     * @create: 2025-03-29 14:21:49
     */
    @OpenApi
    public Return getExamInterviewListByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.containsKey("pageIndex") ? cdoRequest.getInteger("pageIndex") : 0;
        int recordSize = cdoRequest.containsKey("recordSize") ? cdoRequest.getInteger("recordSize") : 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = examInterviewDao.getExamInterviewListByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = examInterviewDao.getExamInterviewListByConditionCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
